function [] = disp2file(myobject, varargin)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% This function is a general purpose function to display a text either on STDOUT (if no additional argument is passed)
	% or on the specified log file (passed as an optional argument).
	%
	% If no log file is specified: this function simply displays the text on STDOUT.
	% If a log file is specified and the string is not empty: this function appends the text at the bottom of the logfile.
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Inputs:
	% myobject:			string or anything
	% varargin{1}:		string (output file where the text needs to be appended)	
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	if length(varargin) >= 1
		outputFile = varargin{1};
	else
		outputFile = {};
	end
	
	if length(varargin) >= 2
		alsoDisplayToStdOutput = varargin{2};
	else
		alsoDisplayToStdOutput = false;
	end

	if isempty(varargin{1})
		disp(myobject);
	else
		fileID = fopen(outputFile,'a');
		mytext = matlab.unittest.diagnostics.ConstraintDiagnostic.getDisplayableString(myobject);
		mytext = myobject;
		fprintf(fileID,sprintf('%s\n', mytext));	
		fclose(fileID);
		
		if alsoDisplayToStdOutput
			disp(mytext);
		end
	end
end